using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Ink;

namespace Haidou.Wpf.Util.Converters;

public class StylusTipToBool : IValueConverter
{
	public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
	{
		return value is not StylusTip tip || parameter is not string param ? DependencyProperty.UnsetValue : tip.ToString().Contains(param);
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		string? param = parameter as string;

		if (value is not bool selection || !selection)
		{
			return DependencyProperty.UnsetValue;
		}

		return string.IsNullOrEmpty(param) ? StylusTip.Rectangle : (object)(param.Equals("Ellipse") ? StylusTip.Ellipse : StylusTip.Rectangle);
	}
}